package com.fallsvc.chatroom.config;

import com.fallsvc.chatroom.controller.TestWebSocketAPI;
import com.fallsvc.chatroom.controller.WebSocketAPI;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

/**
 * @auther falls_vc
 * description:
 * @date 2025/4/30  20:54
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Resource
    private TestWebSocketAPI testWebSocketAPI;
    @Resource
    private WebSocketAPI webSocketAPI;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
//        registry.addHandler(testWebSocketAPI,"/test");
        registry.addHandler(webSocketAPI,"/WebSocketMessage")
                //加上这个拦截器，HttpSession中attribute 的键值对的值 添加到WebSocketSession
                .addInterceptors(new HttpSessionHandshakeInterceptor());
    }
}
